
//
// 120309 - (AH) - Huset.
//

package org.soekrat.engine.io;

import java.util.ArrayList;
import java.util.List;

import org.soekrat.engine.SoekratName;

import com.google.gson.GsonBuilder;

/**
 * <p>
 *   Data that is a Soekrat response to a visitor's request suitable for 
 *   server client protocol serialization (for example using JSON).
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class SoekratResponse 
{
  /**
   * <p>
   *   {@link #visitor(String)}.
   * </p>
   */
  public String visitor=null;
  
  /**
   * <p>
   *   {@link #ceId(String)}.
   * </p>
   */
  public String ceId=null;
  
  /**
   * <p>
   *   {@link #chatInput(String)}.
   * </p>
   */
  public String chatInput=null;
  
  public List<String> m_chatOutputSoekratNames=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public SoekratResponse(){}
  
  /**
   * <p>
   *   Sets name that identifies visitor.
   * </p>
   * @param v Name.
   * @return {@code this}.
   */
  public SoekratResponse visitor(String v){ visitor=v; return this; }
  
  /**
   * <p>
   *   Sets id that identifies the conversation element.
   * </p>
   * <p>
   *   If not given requests a new conversation.
   * </p>
   * @param v Id.
   * @return {@code this}.
   */
  public SoekratResponse ceId(String v){ ceId=v; return this; }
  
  /**
   * <p>
   *   Chat input from the visitor that caused this response.
   * </p>
   * @param v Chat input.
   * @return {@code this}.
   */
  public SoekratResponse chatInput(String v){ chatInput=v; return this; }
  
  /**
   * <p>
   *   Adds
   *   {@link SoekratName} of Soekrat engine response.
   * </p>
   * @param name Name.
   * @return {@code this}.
   */
  public SoekratResponse addChatOutputSoekratName(SoekratName name)
  {
    if (m_chatOutputSoekratNames==null) 
      m_chatOutputSoekratNames=new ArrayList<String>();
    
    m_chatOutputSoekratNames.add(name.getPure());
    
    return this;
  }
  
  /**
   * <p>
   *   Gets JSON code for {@code this}.
   * </p>
   * @return JSON code.
   */
  public String toJson()
  {
    return new GsonBuilder().setPrettyPrinting().create().toJson(this);
  }
  
}
